package everyday3;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;

/**
 * @Author: Siantar
 * @Date: 2023-07-13-13:59
 * @Description: 1.0
 */
public class T2216 {
    public int minDeletion(int[] nums) {
        Deque<Integer> stack = new LinkedList<>();
        for (int num : nums) {
            if (stack.size() % 2 != 0 && stack.getLast() == num) {
                continue;
            }
            stack.addLast(num);
        }
        return nums.length - stack.size() + (stack.size() % 2 == 0 ? 0 : 1);
    }
}
